home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / stay42.zip / STAYXIT.420 < prev   
Text File  |  1986-08-03  |  3KB  |  85 lines

  1. {****************************************************************************}
  2. {                       S T A Y X I T   .   I N C                            }
  3. {****************************************************************************}
  4. {----------------------------------------------------------------------------}
  5. {  Stay_Xit Check Terminate Keys                                             }
  6. {                                                                            }
  7. {  Clean up the Program ,Free the Environment block, the program segment     }
  8. {  memory and return to Dos. Programs using this routine ,must be the        }
  9. {  last program in memory, else ,a hole will be left causing Dos             }
  10. {  to take off for Peoria.                                                   }
  11. {----------------------------------------------------------------------------}
  12. Procedure Stay_Xit;
  13. {
  14.        This code reinstates those interrupts that will not be
  15.        restored by DOS. Interrupts 22,23,24 (hex) are restored
  16.        from the Current PSP during termination.
  17. }
  18.   VAR
  19.    PSPvector22: vector absolute Cseg:$0A;
  20.    PSPvector23: vector absolute Cseg:$0E;
  21.    PSPvector24: vector absolute Cseg:$12;
  22.  
  23.    DOSvector22: vector absolute 0:$88;
  24.    DOSvector23: vector absolute 0:$8C;
  25.    DOSvector24: vector absolute 0:$90;
  26.  
  27.     Begin { Block }
  28.  
  29.       Writeln ('Stay-Resident program Terminated') ;
  30.  
  31.       Inline($FA);                     {Disable interrupts}
  32.  
  33.           { Restore Disk Interrupt Service Routine  }
  34.  
  35.       Regs.Ax := $2500 + BIOSI13;
  36.       Regs.Ds := BIOS_INT13.CS;
  37.       Regs.Dx := BIOS_INT13.IP;
  38.       Intr ($21,Regs);
  39.  
  40.             { Restore Keyboard Interrupt Service Routine  }
  41.  
  42.       Regs.Ax := $2500 + BIOSI16;
  43.       Regs.Ds := BIOS_INT16.CS;
  44.       Regs.Dx := BIOS_INT16.IP;
  45.       Intr ($21,Regs);
  46.  
  47.             { Restore Timer Interrupt Service Routine  }
  48.  
  49.       Regs.Ax := $2500 + BIOSI8;
  50.       Regs.Ds := BIOS_INT8.CS;
  51.       Regs.Dx := BIOS_INT8.IP;
  52.       Intr ($21,Regs);
  53.  
  54.             { Restore DOS 21 Interrupt Service Routine  }
  55.  
  56.       Regs.Ax := $2500 + DOSI21;
  57.       Regs.Ds := DOS_INT21.CS;
  58.       Regs.Dx := DOS_INT21.IP;
  59.       Intr ($21,Regs);
  60.  
  61.             { Restore DOS 28 Interrupt Service Routine  }
  62.  
  63.       Regs.Ax := $2500 + DOSI28;
  64.       Regs.Ds := DOS_INT28.CS;
  65.       Regs.Dx := DOS_INT28.IP;
  66.       Intr ($21,Regs);
  67.  
  68.    { Move Interrupt Vectors 22,23,24 to our PSP from where DOS will restore }
  69.  
  70.       PSPvector22 := DOSvector22;         { Terminate vector }
  71.       PSPvector23 := DOSvector23;         { Cntrl-C vector   }
  72.       PSPvector24 := DOSvector24;         { Critical vector  }
  73.  
  74.       Inline($FB);                        {Re-enable interrupts}
  75.  
  76.       Regs.Ax := $49 shl 8 + 0 ;   { Free Allocated Block function}
  77.       Regs.Es := MemW[Cseg:$2C] ;  { Free environment block       }
  78.       MsDos( Regs ) ;
  79.  
  80.       Regs.Ax := $49 shl 8 + 0 ;    { Free Allocated Block function}
  81.       Regs.Es := Cseg ;             { Free Program                 }
  82.       MsDos( Regs ) ;
  83.  
  84.    End  { StayXit };
  85.